import os
from langchain.agents import *
#from langchain.llms import OpenAI
from langchain_community.llms import Tongyi
os.environ["DASHSCOPE_API_KEY"] = "sk-10920ad0a9d542af96353edd7ab3e613"

from langchain.sql_database import SQLDatabase

db_user = "root"
db_password = "root"
db_host = "192.168.238.101"
db_name = "langchain_yangruofei"
db = SQLDatabase.from_uri(f"mysql+pymysql://{db_user}:{db_password}@{db_host}/{db_name}")

from langchain.chains import create_sql_query_chain

llm = Tongyi()
chain = create_sql_query_chain(llm,db)
response = chain.invoke({"question":"How many students are there"})

print(response)

result_sql=db.run(response)
print(result_sql)